/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 74646
 * Date: 2022-02-26
 * Time: 18:23
 */
import java.util.Stack;

//比较含退格的字符串
public class Test1 {
    public static void main(String[] args) {
        String s = "a#c";
        String t = "b";
        System.out.println(backspaceCompare(s, t));
    }
    public static boolean backspaceCompare(String s, String t) {
        int size1 = 0;
        int size2 = 0;
        Stack<Character> stack1 = new Stack<>();
        Stack<Character> stack2 = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char chs = s.charAt(i);
            if (isOperstion(chs) == false) {
                stack1.push(chs);
                size1++;
            } else {
                if (!stack1.empty()) {
                    stack1.pop();
                    size1--;
                }
            }
        }
        for (int j = 0; j < t.length(); j++) {
            char cht = t.charAt(j);
            if (isOperstion(cht) == false) {
                stack2.push(cht);
                size2++;
            } else {
                if (!stack2.empty()) {
                    stack2.pop();
                    size2--;
                }
            }
        }
        boolean flag = false;
        if (stack1.empty() && stack2.empty()) {
            flag = true;
        }
        while(!stack1.empty() && !stack2.empty()) {
            if(stack1.peek() != stack2.peek()){
                return false;
            }
            stack1.pop();
            stack2.pop();
        }
        return stack1.empty() && stack2.empty();
    }
    public static boolean isOperstion(char s){
        if(s =='#'){
            return true;
        }
        return false;
    }
}
